package com.sscw.tcp.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import com.sscw.tcp.entity.MRecordTaskDailyPO;
import com.sscw.tcp.mapper.MRecordTaskDailyExtMapper;
import com.sscw.tcp.mapper.MRecordTaskDailyMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;

@Repository
@AllArgsConstructor
public class MRecordTaskDailyDAO extends BaseDAO<MRecordTaskDailyMapper, MRecordTaskDailyPO> {

    private final MRecordTaskDailyExtMapper mRecordTaskDailyExtMapper;

    public List<MRecordTaskDailyPO> findUserTodayList(Long userId, LocalDate today) {
        LambdaQueryWrapper<MRecordTaskDailyPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MRecordTaskDailyPO::getUserId, userId);
        queryWrapper.eq(MRecordTaskDailyPO::getRecordDate, today);
        return getBaseMapper().selectList(queryWrapper);
    }

    public List<MRecordTaskDailyPO> findUserTodayAction(Long userId, LocalDate today, Integer action) {
        LambdaQueryWrapper<MRecordTaskDailyPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MRecordTaskDailyPO::getUserId, userId);
        queryWrapper.eq(MRecordTaskDailyPO::getRecordDate, today);
        queryWrapper.eq(MRecordTaskDailyPO::getAction, action);
        return getBaseMapper().selectList(queryWrapper);
    }

    public int updateCompleteTask(Long userId, LocalDate today) {
        return mRecordTaskDailyExtMapper.updateCompleteTask(userId, today);
    }
}
